package soilApi

import (
	"context"
	"newwater/app/soil/cmd/rpc/pb"
	"newwater/common/xerr"

	"newwater/app/soil/cmd/api/internal/svc"
	"newwater/app/soil/cmd/api/internal/types"

	"github.com/tal-tech/go-zero/core/logx"
)

type QuerySoilLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewQuerySoilLogic(ctx context.Context, svcCtx *svc.ServiceContext) QuerySoilLogic {
	return QuerySoilLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}
var ErrUserNoExistsError = xerr.NewErrMsg("查询失败")
func (l *QuerySoilLogic) QuerySoil(req types.Username) (resp *types.SoilRet, err error) {
	soils, err := l.svcCtx.SoilRpc.FindSoilByUserName(l.ctx,&pb.Username{
		Username: req.Username,
	})
	if err != nil {
		return nil, err
	}

	return &types.SoilRet{
		Code: 200,
		Msg:  "查询成功",
		Data: soils.Soils,
	},nil

}
